<script>
import * as echarts from 'echarts';

export default {
  data() {
    return {
      userCount: 0,
      fileCount: 0,
      articleCount: 0,
      questionCount: 0,
    }
  },
  mounted() {
    var chartDom = document.getElementById('a');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
      title: {
        text: '各季度用户注册数量',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ['第一季度', '第二季度', '第三季度', '第四季度']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [150, 230, 224, 218, 135, 147, 260],
          type: 'line'
        },
        {
          data: [150, 230, 224, 218, 135, 147, 260],
          type: 'bar'
        }
      ],
      tooltip: {
        trigger: 'axis', // 悬浮时触发
        formatter: '{b}: {c}' // 显示系列名称和数据值
      },
      color: ['#22e3c6', '#d5748b'], // 设置折线和柱状图的颜色

    };


    var pieDom = document.getElementById('b');
    var pieChart = echarts.init(pieDom);
    var PieOption = {
      title: {
        text: '各季度注册用户比例',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
        formatter: '{b}: {c} ({d}%)' // 显示名称、数值和比例
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },

      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: '60%',
          data: [],
          label: {
            show: true,
            position: 'inside',
            formatter: '{d}%'
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    this.request.get('/echarts/loginNumber')
        .then(res => {
          console.log(res.list)
          option.series[0].data = res.list
          option.series[1].data = res.list
          myChart.setOption(option);

          PieOption.series[0].data = [
            {name: "第一季度", value: res.list[0]},
            {name: "第二季度", value: res.list[1]},
            {name: "第三季度", value: res.list[2]},
            {name: "第四季度", value: res.list[3]}
          ]
          pieChart.setOption(PieOption);


        })

  },
  created() {
    this.getUserCount()
    this.getFileCount()
    this.getArticleCount()
    this.getQuestionCount()
  },
  methods: {
    getUserCount() {
      this.request.get('/user/getUserCount')
          .then(res => {
            this.userCount = res.count
          })
    },
    getFileCount() {
      this.request.get('/file/getFileCount')
          .then(res => {
            this.fileCount = res.count
          })
    },
    getArticleCount() {
      this.request.get('/article/getArticleCount')
          .then(res => {
            this.articleCount = res.count
          })
    },
    getQuestionCount() {
      this.request.get('/question/getQuestionCount')
          .then(res => {
            this.questionCount = res.count
          })
    },

  }
}
</script>

<template>
  <div>

    <el-row :gutter="10" style="margin-bottom: 30px">
      <el-col :span="6">
        <el-card style="color:#67C23A;font-size: 20px">
          <div style="text-align: center"><i class="el-icon-user"></i> 用户总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            {{userCount}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color:#F56C6C;font-size: 20px">
          <div style="text-align: center"><i class="el-icon-s-order"></i>试题总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            {{questionCount}}

          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color:#E6A23C;font-size: 20px">
          <div style="text-align: center"><i class="el-icon-edit"></i>文章总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            {{articleCount}}

          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color:#409EFF;font-size: 20px">
          <div style="text-align: center"><i class="el-icon-files"></i>文件总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            {{fileCount}}

          </div>
        </el-card>
      </el-col>

    </el-row>

    <el-row>
      <el-col :span="12">
        <div id="a" style="width: 500px;height: 500px"></div>
      </el-col>
      <el-col :span="12">
        <div id="b" style="width: 500px;height: 600px"></div>
      </el-col>
    </el-row>
  </div>
</template>

<style>

</style>